﻿using B.S.BasicData.Domain;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Infrastructure.Interfance;
using B.S.BasicData.Read.Apilication.Common.Leave;
using MediatR;

namespace B.S.BasicData.Read.Apilication.Handler.Leave
{
    public class GetDepartmentCommandHandle:IRequestHandler<GetDepartmentCommand,ApiResult<string>>
    {
        private readonly IBaseRepository<DepartmentModel> DepartDal;
        private readonly IBaseRepository<UserModel> UserDal;
        public GetDepartmentCommandHandle(IBaseRepository<DepartmentModel> departDal, IBaseRepository<UserModel> userDal)
        {
            DepartDal = departDal;
            UserDal = userDal;
        }

        public Task<ApiResult<string>> Handle(GetDepartmentCommand request, CancellationToken cancellationToken)
        {
            ApiResult<string> result = new ApiResult<string>();
            var info = DepartDal.GetAll().FirstOrDefault(x => x.DepartmentId == request.DepartmentId).ParentId;

            var user = UserDal.GetAll().FirstOrDefault(x => x.UserId == info).UserName;

            result.Code = ApiEnum.Success;
            result.Message = "部门领导查询成功";
            result.Data = user.ToString();
            return Task.FromResult(result);
        }



    }
}
